package ar.com.quickmart.classes;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 
 * Class Product
 * 
 * Contiene los datos de un producto.
 * Es utilizado para mostrar en una lista de productos.
 * Implementa Parcelable para que se lo pueda pasar entre activities.
 * 
 * @author RP Software
 *
 */

public class Product implements Parcelable, Purchasable {

	// Variables
	private long barcode;
	private String name;
	private float price;
	private int count;

	public Product() {
		this.name = "";
		this.price = 0;
		this.barcode = 0;
		this.count = 0;
	}
	
	public Product(String name, float price, long barcode, int number) {	
		this.name = name;
		this.price = price;
		this.barcode = barcode;
		this.count = number;		
	}
	
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public float getPrice() {
		return price;
	}

	@Override
	public void setPrice(float price) {
		this.price = price;
	}

	public long getBarcode() {
		return this.getId();
	}

	public void setBarcode(long barcode) {
		this.setId(barcode);
	}

	@Override
	public int getCount() {
		return count;
	}

	@Override
	public void setCount(int number) {
		this.count = number;
	}
	
	@Override
	public long getId() {
		return this.barcode;
	}

	@Override
	public void setId(long id) {
		this.barcode = id;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel out, int flags) {		
		out.writeString(this.name);
		out.writeFloat(this.price);
		out.writeLong(this.barcode);
		out.writeInt(this.count);		
	}

    public static final Parcelable.Creator<Product> CREATOR = new Parcelable.Creator<Product>() {
        public Product createFromParcel(Parcel in) {
            return new Product(in);
        }

        public Product[] newArray(int size) {
            return new Product[size];
        }
    };
    
    public Product(Parcel in) {
    	this.name = in.readString();
    	this.price = in.readFloat();
    	this.barcode = in.readLong();
    	this.count = in.readInt();
    }

}
